package se.jocke.nbrs.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jocke
 */
public final class RestServiceGroup {

    private String name;

    private Map<String, RestService> services;

    public RestServiceGroup() {
        this.services = new HashMap<String, RestService>();
    }

    public RestServiceGroup(String name) {
        this.name = name;
        this.services = new HashMap<String, RestService>();
    }

    public RestServiceGroup(String name, Map<String, RestService> services) {
        this.name = name;
        this.services = services;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, RestService> getServices() {
        return services;
    }

    public List<RestService> getServicesAsList() {
        return new ArrayList<RestService>(services.values());
    }

    public void setServices(Map<String, RestService> services) {
        this.services = new HashMap<String, RestService>(services);
    }

    public void add(RestService restService) {
        services.put(restService.getName(), restService);
    }

    public void update(RestService restService) {
        services.put(restService.getName(), restService);
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 67 * hash + (this.services != null ? this.services.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RestServiceGroup other = (RestServiceGroup) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if (this.services != other.services && (this.services == null || !this.services.equals(other.services))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "RestServiceGroup{" + "name=" + name + ", services=" + services + '}';
    }

}
